

class InputThing < Thing

  attribute :content

  def initialize options = {}
    @options = options.stringify_keys
  end

  def recieve e
    if content = e.params[form_id(:value)]
      @content = content
    end
    super
  end

  def render e
    content
  end

  def creator e
    div = Element.new(:div)
    if @options['label']
      div.append_child Element.new('label', @options['label'], :for => form_id(:value))
      div.append_child ' '
    end
    div.append_child Element.new(
        :input,
        :type => 'text',
        :name => form_id(:value),
        :id => form_id(:value),
        :value => @content
      )
    div
  end

  def get_data
    { 'content' => content }
  end

  def fill_data h
    @content = h['content'] || h['text']
  end
end